//
//  HMFeatrueCell.m
//  OC新浪微博
//
//  Created by wyman on 16/4/13.
//  Copyright © 2016年 wyman. All rights reserved.
//

#import "HMFeatrueCell.h"
#import <Masonry.h>
#import "HMMainViewController.h"
#import "AppDelegate.h"
@implementation HMFeatrueCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        //添加图片
        [self.contentView addSubview:self.iconView];
        [self.contentView addSubview:self.button];

        self.iconView.frame = self.contentView.frame;

        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView).offset(-160);
        }];

        
    
    }

    return self;
}
-(void)setIndex:(int)index
{
    
    self.button.hidden = YES;

    _index = index;
    self.iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%d",index+1]];
    
}



-(UIImageView *)iconView
{
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc]init];

    }
    return _iconView;
}
-(UIButton *)button
{
    if (_button == nil) {
        _button = [[UIButton alloc]init];
        [_button setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        
        [_button setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];;
        

        [_button setTitle:@"进入微博" forState:UIControlStateNormal];
        [_button sizeToFit];
    }

    return _button;
}

/**
 *  动画效果
 */
-(void)startRotate;
{
    self.button.hidden = NO;
    
    self.button.transform = CGAffineTransformMakeScale(0, 0);
    
    [self.button addTarget:self action:@selector(startClick) forControlEvents:UIControlEventTouchUpInside];
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:0 animations:^{
        self.button.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        HMLog("动画完成");
    }];


}

//点击事件
-(void)startClick{
    
    UIViewController *controller = [[HMMainViewController alloc]init];
    
   
    [(AppDelegate *)([UIApplication sharedApplication].delegate) switchViewController:controller];


}

@end
